﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wintellect.Sterling;

namespace Caramel.Sterling
{
	public class SterlingRepository<T> : IRepository<T> where T : class, new()
	{
		public SterlingRepository(ISterlingDatabaseInstance databaseInstance)
		{
			this.DatabaseInstance = databaseInstance;
		}

		public ISterlingDatabaseInstance DatabaseInstance { get; set; }

		public T Get(object id)
		{
			return this.DatabaseInstance.Load<T>(id);
		}

		public void Save(T entity)
		{
			this.DatabaseInstance.Save<T>(entity);
		}

		public void Delete(T entity)
		{
			this.DatabaseInstance.Delete<T>(entity);
		}

		public void DeleteAll()
		{
			this.DatabaseInstance.Truncate(typeof(T));
		}

		public IQueryable<T> All
		{
			get
			{
				//var key = this.DatabaseInstance.GetKeyType(typeof(T));

				//return
				//    this.DatabaseInstance.Query<

				throw new NotImplementedException();
			}
		}
	}
}
